﻿using System;

namespace SharpSqlAnalyzer.nodes
{
	// Token: 0x02000357 RID: 855
	public class TTableList : TParseTreeNodeList
	{
		// Token: 0x0600239A RID: 9114 RVA: 0x0033793B File Offset: 0x00335B3B
		public void removeTable(int index)
		{
			if (index >= 0 && index < base.size())
			{
				this.getTable(index).setChanged();
				base.removeElementAt(index);
			}
		}

		// Token: 0x0600239C RID: 9116 RVA: 0x00337965 File Offset: 0x00335B65
		public virtual void addTable(TTable table)
		{
			base.addElement(table);
		}

		// Token: 0x0600239D RID: 9117 RVA: 0x00337970 File Offset: 0x00335B70
		public virtual void addTableByTableRefernce(TTableReference tableref)
		{
			bool flag = false;
			for (int i = 0; i < base.size(); i++)
			{
				if (this.getTable(i).isTableRefBelongToThisTable(tableref))
				{
					this.getTable(i).Tablerefs.addTableReference(tableref);
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				this.addTable(new TTable(tableref.objectname));
			}
		}

		// Token: 0x1700078E RID: 1934
		public TTable this[int position]
		{
			get
			{
				if (position < 0 || position >= base.size())
				{
					throw new IndexOutOfRangeException();
				}
				return (TTable)this.elementAt(position);
			}
		}

		// Token: 0x0600239F RID: 9119 RVA: 0x003379EA File Offset: 0x00335BEA
		public virtual TTable getTable(int position)
		{
			if (position < base.size())
			{
				return (TTable)this.elementAt(position);
			}
			return null;
		}

		// Token: 0x060023A0 RID: 9120 RVA: 0x00337A03 File Offset: 0x00335C03
		internal override void addParseTreeNode(object arg1)
		{
			this.addTable((TTable)arg1);
		}

		// Token: 0x060023A1 RID: 9121 RVA: 0x00337A14 File Offset: 0x00335C14
		public virtual int checkColumnReferenceInTables(TObjectName crf)
		{
			int result = -1;
			if (crf.ObjectToken == null)
			{
				return -2;
			}
			for (int i = 0; i < base.size(); i++)
			{
				TTable table = this.getTable(i);
				if (table.AliasClause != null)
				{
					if (string.Compare(table.AliasClause.AliasName.ToString(), crf.ObjectToken.ToString(), StringComparison.CurrentCultureIgnoreCase) == 0)
					{
						crf.ObjectToken.DbObjType = EDbObjectType.table_alias;
						return i;
					}
				}
				else if (table.TableType == ETableSource.objectname)
				{
					if (string.Compare(table.TableName.ObjectToken.ToString(), crf.ObjectToken.ToString(), StringComparison.CurrentCultureIgnoreCase) == 0)
					{
						crf.ObjectToken.DbObjType = EDbObjectType.table;
						return i;
					}
					if (string.Compare(table.TableName.ObjectToken.toUnQuotedString(), crf.ObjectToken.toUnQuotedString(), StringComparison.CurrentCultureIgnoreCase) == 0)
					{
						crf.ObjectToken.DbObjType = EDbObjectType.table;
						return i;
					}
				}
			}
			return result;
		}
	}
}
